﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using System.Data;

namespace DataAccessLayer {
    public class ContractRepository : DataProvider {
        public int insert(String contractType, float price, String employeeID, String termID, String contractID) {
           
            String sql = "INSERT INTO HopDong(MaHopDong, LoaiHopDong, GiaThanh, MaNhanVien, MaCongTy, NgayKy) VALUES('{5}', '{0}', {1}, '{2}', '{3}', '{4}')";
            sql = string.Format(sql, contractType, price, employeeID, termID, DateTime.Now, contractID);
            if (this.executeQuery(sql) > 0){
                return 1;
            }
            else
                return -1;
        }

        public void insertDetail(String contractID, int productID, int quanlity, String design) {
            String sql = String.Format("INSERT INTO ChiTietHopDong(MaHopDong, MaSanPham, SoLuong, BanThietKe) VALUES('{0}', {1}, {2}, '{3}')", contractID, productID, quanlity, design);
            this.executeQuery(sql);
        }

        public DataTable getContract1(String contractID) {
            String sql = string.Format("SELECT * FROM HopDong WHERE MaHopDong LIKE '%{0}%' AND TinhTrang = 0", contractID);
            return this.executeQueryDataTable(sql);
        }

        public void updateContract2(String contractID) {
            String sql = string.Format("UPDATE HopDong SET TinhTrang = 1 WHERE MaHopDong = '{0}'", contractID);
            this.executeNonQuery(sql);
        }

        public void liquidateContract(String id, String contractID, String info) {
            String sql = string.Format("INSERT INTO BanThanhLyHopDong(MaThanhLyHopDong, MaHopDong, NgayLap, ThongTin) VALUES('{0}', '{1}', '{2}', '{3}')", id, contractID, DateTime.Now, info);
            this.executeNonQuery(sql);
        }
    }
}
